package com.acwing.partition4;

import java.io.*;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;

/**
 * @author `RKC`
 * @date 2022/1/22 16:53
 */
public class AC362区间 {

    private static final int N = (int) (1e5 + 10), M = 3 * N, INF = 0x3f3f3f3f;
    private static int[] head = new int[N], element = new int[M], next = new int[M], weight = new int[M];
    private static int[] dist = new int[N];
    private static boolean[] inQueue = new boolean[N];
    private static Queue<Integer> queue = new ArrayDeque<>(N);

    private static int n = 0, idx = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = Integer.parseInt(reader.readLine());
        Arrays.fill(head, -1);
        for (int i = 1; i < N; i++) {
            //sum[i]>=sum[i-1]
            createEdge(i - 1, i, 0);
            //sum[i]-sum[i-1]<=1
            createEdge(i, i - 1, -1);
        }
        for (int i = 0; i < n; i++) {
            String[] s = reader.readLine().split("\\s+");
            int u = Integer.parseInt(s[0]) + 1, v = Integer.parseInt(s[1]) + 1, w = Integer.parseInt(s[2]);
            //sum[v]-sum[u - 1]>=w
            createEdge(u - 1, v, w);
        }
        writer.write(spfa() + "\n");
        writer.flush();
    }

    private static int spfa() {
        Arrays.fill(dist, -INF);
        dist[0] = 0;
        queue.add(0);
        inQueue[0] = true;
        while (!queue.isEmpty()) {
            int u = queue.poll();
            inQueue[u] = false;
            for (int i = head[u]; i != -1; i = next[i]) {
                int v = element[i];
                if (dist[v] < dist[u] + weight[i]) {
                    dist[v] = dist[u] + weight[i];
                    if (inQueue[v]) continue;
                    queue.add(v);
                    inQueue[v] = true;
                }
            }
        }
        return dist[50001];
    }

    private static void createEdge(int u, int v, int w) {
        element[idx] = v;
        next[idx] = head[u];
        head[u] = idx;
        weight[idx++] = w;
    }
}
